# Maintainer: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=libdeflate
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7
pkgrel=1
pkgdesc="Heavily optimized library for DEFLATE/zlib/gzip compression and decompression (mingw-w64)"
arch=('any')
url='https://github.com/ebiggers/libdeflate'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/ebiggers/libdeflate/archive/v${pkgver}.tar.gz"
        "001-libdeflate-makefile-mingw-fix.patch")
sha256sums=('a5e6a0a9ab69f40f0f59332106532ca76918977a974e7004977a9498e3f11350'
            '3416c533717a7dda6acf3e0f111ba9478517a7b98bec41821bd019901742cb9b')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-libdeflate-makefile-mingw-fix.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -a "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  make PREFIX=${MINGW_PREFIX}
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install PREFIX=${MINGW_PREFIX} DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
